
Global.language=getUrlParameter("request-locale");


require(["widgets/opManagers/GlobalOpManager",
         "widgets/thematicManager/ThematicManager",
         "widgets/icons/IconBase","esri/geometry/Point",
         "dojo/topic",
         "dojo/domReady!"],function(GlobalOpManager,ThematicManager,IconBase,Point,Topic){
	Global.globalOpManager=new GlobalOpManager({global:Global});
	esri.config.defaults.io.alwaysUseProxy=false;
	esri.config.defaults.io.proxyUrl="proxy.jsp";
	getEID(getUrlParameter("user-id"));
	getRights(Topic,Point);
});
 

function getRights(Topic,Point){
	//获取权限
	$.ajax({
		type:'get',
		url:Global.useRight?"/mgis/services/userservice/":'./right.js',//
		data:{
			usereid:""
		},
		dataType:'json',
		success:function(response){
			processRight(response);
			getInitParam(Topic,Point);
			if(dijit.byId("mapW"))dijit.byId("mapW").initLayers();
		},
		error:function(response){
			console.log("获取权限出错");
		}
	});
}

 
function getInitParam(Topic,Point){
	showTxtLoading();
	$.ajax({
		type:'post',
		url:'/mgis/services/queryservice/getuserextent?r='+Math.random(),
		data:{
//			eid:Global.loginUserEID
		},
		dataType:'json',
		success:function(response){
			callback=function(){
				setLanguage();
				hideTxtLoading();
			};
			if(Global.mapLoaded){
				callback();
			}else{
				Topic.subscribe("map_loaded",callback);
			}
		},
		error:function(response){
			hideTxtLoading();
		}
	});
}

 

function setLanguage(){
	var enAndcn = ioc.ENandCN;
	var classname = "";
	var type = "";
	var value = "";
	Global.enLayer.setVisibility(Global.language=="zh-en");
	Global.cnLayer.setVisibility(Global.language!="zh-en");
	for (var i = 0; i < enAndcn.length; i++){
		classname = enAndcn[i].classname;
		type = enAndcn[i].type;
		var doms = dojo.query("."+classname+"");//DOM结点
		if (doms){
			for (var j = 0; j < doms.length; j++){
				var dom = doms[j];
				if (Global.language == "zh-en"){//英文
    				value = enAndcn[i].en;  			
            	}else{//中文
            		value = enAndcn[i].cn;
            	}
    			if (type == "text"){
    				dom.innerHTML = value;
    			}else if (type == "title"){
    				dom.title = value;
    			}else{
    				
    			}
			}
		}
	}
}


function processRight(){
 
	//Store权限
	Global.storeDataRangeRegion=" 0=0 ";
	//不带前缀、Store权限
	Global.storeDataRange=" 0=0 ";
	
	//Other权限
	//带前缀、Other数据权限
	Global.dataRangeRegion=" 0=0 ";
	//不带前缀、Other数据权限
	Global.dataRange=" 0=0 ";
 
}

function getEID(userid){
	$.ajax({
		type:'post',
		url:'/mgis/services/queryservice/geteid',
		data:{
			userid:userid
		},
		async:false,
		dataType:'json',
		success:function(response){
			Global.EID = response;
		},
		error:function(response){
		}
	});
}
//esri.config.defaults.io.errorHandler=function(){console.log(arguments)}